﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JobOffersBrowser.Helpers;

namespace JobOffersBrowser.ViewModels
{
    public class MainViewModel : ViewModelBase
    {
        private List<IndustryViewModel> industries;
        private IndustryViewModel currentIndustry;
        private List<OfferViewModel> offers;
        private OfferViewModel currentOffer;

        public MainViewModel() { }

        public OfferViewModel CurrentOffer
        {
            get
            {
                return currentOffer;
            }
            set
            {
                if (this.currentOffer != value)
                {
                    currentOffer = value;
                    OnPropertyChanged("CurrentOffer");
                }
            }
        }

        public List<OfferViewModel> Offers
        {
            get
            {
                return offers;
            }
            set
            {
                if (this.offers != value)
                {
                    offers = value;
                    OnPropertyChanged("Offers");
                }
            }
        }

        public IndustryViewModel CurrentIndustry
        {
            get
            {
                return currentIndustry;
            }
            set
            {
                if (this.currentIndustry != value)
                {
                    currentIndustry = value;
                    Offers = new List<OfferViewModel>(ViewModelsHelper.GetOffersByIndustry(CurrentIndustry));
                    OnPropertyChanged("CurrentIndustry");
                }
            }
        }

        public List<IndustryViewModel> Industries
        {
            get
            {
                if (this.industries == null)
                {
                    industries = ViewModelsHelper.GetAllIndustries().ToList();
                    CurrentIndustry = industries.FirstOrDefault();
                }
                return industries;
            }
            set
            {
                if (this.industries != value)
                {
                    industries = value;
                    OnPropertyChanged("Industries");
                }
            }
        }
    }
}
